<script>
/*
 * Copyright (c) 2012-2013 RockStor, Inc. <http://rockstor.com>
 * This file is part of RockStor.
 *
 * RockStor is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 *
 * RockStor is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
</script>

<script>
$(document).ready(function() {
  $('#cron').cron({
  initial: "42 3 * * 5",
  customValues: {
    "5 minutes" : "*/5 * * * *",
    "10 minutes": "*/10 * * * *",
    "20 minutes": "*/20 * * * *",
    "30 minutes" : "*/30 * * * *",
    "45 minutes" : "*/45 * * * *",
  },
    useGentleSelect: true
});
});
</script>

{{#unless replicaId}}
<div class="row">
  <div class="col-md-8">
<div class="panel panel-default">
<div class="panel-heading">Add a new replication task</div>

    <div class="panel-body">
      <form  class="form-horizontal" id="replication-task-create-form" name="aform">
	<div class="messages"></div>
	<div class="form-group">
	  <label class="col-sm-4 control-label" for="task_name">Task name<span class="required"> *</span></label>
	  <div class="col-sm-6">
	    <input class="form-control" type="text" id="task_name" name="task_name" placeholder="Task name" title="A unique name for this replication task" >
	  </div>
	</div>
	<div class="form-group">
	  <label class="col-sm-4 control-label" for="share">Share to replicate<span class="required"> *</span></label>
	  <div class="col-sm-6">
	    <select class="form-control" id="share" name="share" title="Share to replicate">
	      {{#each shares}}
	      <option value="{{this.name}}"> {{this.name}} </option>
	      {{/each}}

	    </select>
	  </div>
	</div>
	<div class="form-group">
	  <label class="col-sm-4 control-label" for="appliance">Remote appliance<span class="required"> *</span></label>
	  <div class="col-sm-6">
	    <select class="form-control" id="appliance" name="appliance" title="Share will be replicated to this remote Rockstor appliance.">
	      {{#each appliances}}
	      {{#unless this.current_appliance}}
	      <option value="{{this.ip}}"> {{this.ip}} </option>
	      {{/unless}}
	      {{/each}}

	    </select>
	  </div>
	</div>
	<div class="form-group">
	  <label class="col-sm-4 control-label" for="listener_ip">Remote Listener Address</label>
	  <div class="col-sm-6">
	  <input class="form-control" type="text" id="listener_ip" name="listener_ip" value="{{listener_ip}}"title="If remote appliance's replication service is listening on a different IP address, provide here. If not, appliance's IP address will be used.">
	  </div>
	</div>
	<div class="form-group">
	  <label class="col-sm-4 control-label" for="port">Remore Listener Port<span class="required"> *</span></label>
	  <div class="col-sm-6">
	    <input class="form-control" type="text" id="listener_port" name="listener_port" value="{{listener_port}}" title="Replication meta port on the target appliance. (Default is {{listener_port}})">
	  </div>
	</div>
	<div class="form-group">
	  <label class="col-sm-4 control-label" for="pool">Remote pool<span class="required"> *</span></label>
	  <div class="col-sm-6">
	    <select class="form-control" id="pool" name="pool" title="Share will be replicated to this Pool on the remote Rockstor appliance.">
	      {{#each remote_pools}}
	      <option value="{{this}}"> {{this}}</option>
	      {{/each}}
	    </select>
	  </div>
	</div>
	<div class="form-group">
         <label class="col-sm-4 control-label" for="cron">Replication Frequency</label>
         <div class="row">
           <div class="col-sm-6">
             <div id="cron"></div>
           </div>
         </div>
	</div>

	<div class="form-group">
	  <div class="col-sm-offset-4 col-sm-8">
	    <a id="js-cancel" class="btn btn-default">Cancel</a>
	    <input type="Submit" id="create_replication_task" class="btn btn-primary" value="Submit"></input>
	  </div>
	</div>
      </form>
</div> <!-- panel-body -->
</div><!--panel-default-->
  </div> <!-- col-md-8 -->
</div> <!-- row -->

{{else}}
<div class="row">
  <div class="col-md-8">
    <div class="panel panel-default">
      <div class="panel-heading">Edit Replication task</div>
      <div class="panel-body">
	<form class="form-horizontal" id="replication-task-create-form" name="aform">
	  <div class="messages"></div>
	  <div class="form-group">
	    <label class="col-sm-4 control-label" for="task_name">Task name:</label>
	    <div class="col-sm-6">
	      <input type="text" class="form-control" value="{{replica.task_name}}" disabled="disabled">
	    </div>
	  </div>
	  <div class="form-group">
	    <label class="col-sm-4 control-label" for="share">Share to replicate:</label>
	    <div class="col-sm-6">
	      <input type="text" class="form-control" value="{{replica.share}}" disabled="disabled">
	    </div>
	  </div>
	  <div class="form-group">
	    <label class="col-sm-4 control-label" for="appliance">Remote appliance:</label>
	    <div class="col-sm-6">
	      <input type="text" class="form-control" value="{{replica.appliance}}" disabled="disabled">
	    </div>
	  </div>
	  <div class="form-group">
	    <label class="col-sm-4 control-label" for="listener_ip">Remote Listener Address:</label>
	    <div class="col-sm-6">
	      <input type="text" class="form-control" name="listener_ip" value="{{replica.replication_ip}}">
	    </div>
	  </div>
	  <div class="form-group">
	    <label class="col-sm-4 control-label" for="listener_port">Remote Listener Port:</label>
	    <div class="col-sm-6">
	      <input type="text" class="form-control" name="listener_port" value="{{replica.data_port}}">
	    </div>
	  </div>
	  <div class="form-group">
	    <label class="col-sm-4 control-label" for="pool">Remote pool:</label>
	    <div class="col-sm-6">
	      <input type="text" class="form-control" value="{{replica.dpool}}" disabled="disabled">
	    </div>
	  </div>
	  <div class="form-group">
            <label class="col-sm-4 control-label" for="cron">Replication Frequency</label>
            <div class="row">
              <div class="col-sm  -6">
		<div id="cron"></div>
              </div>
            </div>
	  </div>
	  <div class="form-group">
	    <div class="col-sm-offset-4 col-sm-8">
	      <a id="js-cancel" class="btn btn-default">Cancel</a>
	      <input type="Submit" id="create_replication_task" class="btn btn-primary" value="Submit"></input>
	    </div>
	  </div>
	</form>

      </div> <!-- panel-body -->
    </div><!--panel-default-->
  </div> <!-- col-md-8 -->
</div> <!-- row -->
{{/unless}}
